package com.jy.horny.utils

import android.app.Activity
import android.content.Context
import com.jy.chat.kit.RongIM
import com.jy.horny.R

import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.firebase.Firebase
import com.google.firebase.auth.auth
import com.google.firebase.messaging.FirebaseMessaging
import com.jy.horny.function.login.LoginActivity
import com.lib.module_base.utils.SaveDeviceUtil

object UserUtil {
    /**
     * 退出登录
     */
    fun out(context: Activity) {
        FirebaseMessaging.getInstance().deleteToken()
        RongIM.getInstance().logout()
        if (Firebase.auth.uid != null) {
            Firebase.auth.signOut()
        }
        googleLogin(context).signOut()
        SaveDeviceUtil.clearUserInf()
        LoginActivity.startNew(context)
    }

    /**
     * 删除账号
     */
    fun deleteAccount(context: Activity) {
        FirebaseMessaging.getInstance().deleteToken()
        googleLogin(context).signOut()
        RongIM.getInstance().logout()
        if (Firebase.auth.uid != null) {
            Firebase.auth.signOut()
        }
        SaveDeviceUtil.clearUserInf()
        LoginActivity.startNew(context)
    }

    fun googleLogin(context: Context): GoogleSignInClient {
        val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestId()
            .requestProfile()
            .requestIdToken(context.getString(R.string.default_web_client_id))
            .requestEmail()
            .build()
        //google login setting
        return GoogleSignIn.getClient(context, gso)
    }

}